// import { from } from 'core-js/core/array';
import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';
import { isLogined } from '../utils/tools';
Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home
  },{
    path:"/list",
    name:"List",
    component: ()=>import('../views/List.vue')
  },{
    path:"/cart",
    name:"Cart",
    component: ()=>import('../views/Cart.vue'),
    meta:{
      needLongin:true,
    }
  },{
    path:"/detail",
    name:"Detail",
    component: ()=>import('../views/Detail.vue')
  },{
    path:"/login",
    name:"Login",
    component: ()=>import('../views/Login.vue')
  },{
    path:"/reg",
    name:"Reg",
    component: ()=>import('../views/Reg.vue')
  },{
    path:"/user",
    name:"User",
    component: ()=>import('../views/User.vue'),
    meta:{
      needLongin:true,
    }
  },{
    path:"*",
    name:"pageNotFount",
    component: ()=>import('../views/pageNotFount.vue')
  },
  
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.meta.needLongin) {
    if(isLogined()){
      next()
    }else{
      next({
        name:"Login",
      })
    }
  }else{
    next()
  }
})
export default router
